home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / How_do_the215708792009.psc / Sine & Cosine / Form1.frm next >
Text File  |  2009-07-09  |  4KB  |  125 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   8970
  6.    ClientLeft      =   60
  7.    ClientTop       =   450
  8.    ClientWidth     =   11970
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   598
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   798
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.Timer Timer1 
  15.       Enabled         =   0   'False
  16.       Interval        =   1
  17.       Left            =   3600
  18.       Top             =   2760
  19.    End
  20.    Begin VB.CommandButton Command1 
  21.       Caption         =   "Draw Ellipse"
  22.       Height          =   495
  23.       Left            =   0
  24.       TabIndex        =   0
  25.       Top             =   0
  26.       Width           =   1215
  27.    End
  28. End
  29. Attribute VB_Name = "Form1"
  30. Attribute VB_GlobalNameSpace = False
  31. Attribute VB_Creatable = False
  32. Attribute VB_PredeclaredId = True
  33. Attribute VB_Exposed = False
  34. Dim x, y
  35. Private Function Cosine(Number As Double) As Double
  36.  
  37. '                x^2    x^4    x^6    x^8    x^10   x^12   x^14  x^16
  38. '   cos(x)= 1 - ---- + ---- - ---- + ---- - ---- + ---- - ---- + ---- ......
  39. '                2!     4!     6!     8!     10!    12!    14!   16!
  40.     
  41.     Static PlusMinus As Boolean
  42.     Dim i As Double
  43.     '                       A                A is the upper
  44.     Dim Upper As Double ' -----
  45.     '                       B                B is the lower
  46.     Dim Lower As Double
  47.     
  48.     Cosine = 1
  49.     
  50.     PlusMinus = False
  51.      ' the cosine is infinety function, so i used the For from 2 to a big number
  52.      ' you can change this number but not so big that make the function slow, and not lower than 20
  53.      ' the number should be even number (2,4,6,8,10,12,14,16,18,20....)
  54.     For i = 2 To 150 Step 2
  55.         Upper = Number ^ i
  56.         Lower = Factorial(i)
  57.         PlusMinus = Not (PlusMinus)
  58.         If PlusMinus = True Then
  59.             Cosine = Cosine - (Upper / Lower)
  60.         ElseIf PlusMinus = False Then
  61.             Cosine = Cosine + (Upper / Lower)
  62.         End If
  63.     Next
  64. End Function
  65.  
  66. Private Function Cosine2(Number As Double) As Double
  67.  
  68.     '                  Pi
  69.     'Cos(x) = Sin(x + ---- )
  70.     '                  2
  71.     
  72.     Dim Pi: Pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270192852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133055305488204665213841469519415116094330572703657595919530921861173817326117931051185480744623799627495673518857527248912279381830119491298336733624406566430"
  73.     Cosine2 = Sine(Number + (Pi / 2))
  74. End Function
  75. Private Function Sine(Number As Double) As Double
  76.     
  77. '                x^3    x^5    x^7    x^9    x^11   x^13   x^15  x^17
  78. '   sin(x)= x - ---- + ---- - ---- + ---- - ---- + ---- - ---- + ---- .....
  79. '                3!     5!     7!     9!     11!    13!    15!   17!
  80.     
  81.     Static PlusMinus As Boolean
  82.     Dim i As Double
  83.     Dim Upper As Double
  84.     Dim Lower As Double
  85.     
  86.     Sine = Number
  87.     
  88.     PlusMinus = False
  89.      '  the sine is infinety function, so i used the For from 3 to a big number
  90.      ' you can change this number but not so big that make the function slow, and not lower than 20
  91.      ' the number should be odd number (3,5,7,9,11,13,15,17,19,21....)
  92.     For i = 3 To 151 Step 2
  93.         Upper = Number ^ i
  94.         Lower = Factorial(i)
  95.         PlusMinus = Not (PlusMinus)
  96.         If PlusMinus = True Then
  97.             Sine = Sine - (Upper / Lower)
  98.         ElseIf PlusMinus = False Then
  99.             Sine = Sine + (Upper / Lower)
  100.         End If
  101.     Next
  102. End Function
  103.  
  104. Private Function Factorial(Number As Double) As Double
  105.     'Factorial(x) = x! = 1 * 2 * 3 * 4 * 5 * 6 ...... * x
  106.     Factorial = 1
  107.     For i = 1 To Number
  108.         Factorial = Factorial * i
  109.     Next
  110. End Function
  111.  
  112. Private Sub Command1_Click()
  113.     Me.CurrentX = 300
  114.     Me.CurrentY = 400
  115.  
  116.     Timer1 = True
  117. End Sub
  118.  
  119. Private Sub Timer1_Timer()
  120.     x = x + 5
  121.     x = x Mod 360
  122.     Me.Line -(Sine(x * 3.141 / 180) * 200 + 300, Cosine(x * 3.141 / 180) * 100 + 300)
  123.     Me.Line -(Sin(x * 3.141 / 180) * 200 + 300, Cos(x * 3.141 / 180) * 100 + 300)
  124. End Sub
  125.